unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, 
  Controls, Forms, Dialogs, StdCtrls, ComCtrls;

type
  TMainForm = class(TForm)
    buttCopy: TButton;

    edSource: TEdit;
    edDest: TEdit;

    Label1: TLabel;
    Label2: TLabel;

    ProgressBar: TProgressBar;
    CopyAnimate: TAnimate;

    procedure buttCopyClick(Sender: TObject);
  private
    { Private declarations }

  public

    Procedure CopyBigFile(SrcName,DestName:String);
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.DFM}

{ TForm1 }

procedure TMainForm.CopyBigFile(SrcName, 
                                                                DestName: String);
var
    src,
    dest       :file;

    Buffer  :array[0..4096] of char;  

    fRead,
    fWrite  :integer;

    fSize   :longint;              
 begin
   AssignFile(src,SrcName);
   reset(src,1);

   AssignFile(Dest,DestName);
   rewrite(dest,1);

   fSize:=FileSize(src);

   ProgressBar.Max:=fSize;
   ProgressBar.Min:=0;

   CopyAnimate.Active:=True; //The hien anh ang copy
  repeat
      BlockRead(src,Buffer,SizeOf(Buffer),fRead);
      BlockWrite(dest,Buffer, fRead,fWrite);
      ProgressBar.Position:=ProgressBar.Position+fRead;
  until (fRead = 0) or (fWrite <> fRead);

   CloseFile(src);
   CloseFile(dest);

   CopyAnimate.Active:=False; 

end;

procedure TMainForm.buttCopyClick(Sender: TObject);
begin
  CopyBigFile(edSource.Text,edDest.Text);
  ShowMessage('Finished');
  ProgressBar.Position:=0;
end;

end.
